﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.Collections.Specialized;
using System.IO;
using Vms.DB;
using Vms.Business;
using System.Text;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Util m_util = new Util();
        DB m_db = new DB();
        WriteFile wf = new WriteFile();
        Util.TSession m_session = new Util.TSession();
        try
        {
            m_session.SessionID = Session.SessionID;                                            // lay ra gia tri cua session [system.web.SessionState]
            m_session.UserMSISDN = m_util.GetHeaderValue(Request.Headers, "User-MSISDN");
            m_session.User_ID = m_util.GetHeaderValue(Request.Headers, "User-UID");
            m_session.IP = Request.UserHostAddress;
            m_session.StartTime = DateTime.Now;
            m_util.write_log("-----------", 1);
            m_util.write_log("Main SesionID:" + m_session.SessionID, 1);
            m_util.write_log("IP:" + m_session.IP + ",RequestTime:" + m_session.StartTime.ToLongTimeString() + ",User-MSISDN:" + m_session.UserMSISDN, 1);
            if (m_db.GetUserOnline(m_session.UserMSISDN, m_session.User_ID) == 0)
            {
                m_db.InsertReQuestTbl(m_session);
            }
            string str = "<?xml version='1.0' encoding='ISO-8859-1'?>" +
            "<!DOCTYPE pages SYSTEM 'cellflash.dtd'>" +
            "<pages descr='Samis'>" +
            "<page> <br/>";
            DataSet ds = new DataSet();
            ds = m_db.GetServiceByPage(0);
            DataTable dtb = new DataTable();
            dtb = ds.Tables[0].Clone();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dtb.Rows.Add(ds.Tables[0].Rows[i].ItemArray);
            }
            foreach (DataRow dr in dtb.Rows)
            {
                str += "<a href='" + dr["URL"].ToString().Trim() + "'>" + dr["Text"].ToString().Trim() + "</a><br/>";
            }
            str += "</page>" +
               "</pages>";
            Response.ClearHeaders();
            Response.AddHeader("content-type", "text/xml");
            Response.Write(str);
            wf.WriteStreamFile(str);
            Response.End();
        }
        catch (Exception ex)
        {
            wf.WriteError(ex.ToString());
        }
    }
}